#!/usr/bin/python

import os
import re
import ssh.client
import time
import logging
import pprint
import u110
import u706

logging.basicConfig()
#logging.getLogger('ssh.transport').setLevel(logging.INFO)

pp = pprint.PrettyPrinter(indent=2)


#########################################################
# From properties
#
# Router ID
donglePort = '/dev/ttyUSB0'
dongleMac = "\xDE\x00\x00\x00\x10\xE3\x0C\xD7"
powerMac = "\xD7\x01\x00\x00\x70\xE3\x0C\xD7"
#powerMac = "\x5E\x01\x00\x00\x70\xE3\x0C\xD7"
#
#########################################################





########################################################################
# main

dongle = u110.Dongle(donglePort)
if (dongle.set_forwarder(dongleMac, powerMac)):
  captor = u706.Captor(dongle)
  print "Sleep 1s ..."
  time.sleep(1)
  print "Read data ..."
  (ret, voltage, intensity, power, energy) = captor.readData()
  if (ret):
    print "Ret:",ret, " Voltage:",voltage, " Intensity:",intensity, " Power:",power, " Energy:",energy
  else:
    print "No data from Power Meter ",pp.pformat(powerMac)
  # end if

else:
  print "set_forwarder failed!"

# end main
